﻿using PLCS.Domain.Tasks;
using PLCS.EntityFrameworkCore.EntityFrameworkCore;

namespace PLCS.EntityFrameworkCore.Tasks;

public class PathResultRepository : EfCoreRepository<PLCSDbContext, PathResult, Guid>, IPathResultRepository
{
    public PathResultRepository(IDbContextProvider<PLCSDbContext> dbContextProvider) : base(dbContextProvider)
    {
    }

    public async Task CreatePaths(string start, string end, string paths)
    {
        var pathResult = new PathResult(start, end, paths);
        await InsertAsync(pathResult);
    }

    public async Task<string?> FindPaths(string start, string end)
    {
        var Queryab = await GetQueryableAsync();
        Queryab = Queryab.Where(x => x.Start == start && x.End == end);
        var res = await AsyncExecuter.SingleOrDefaultAsync(Queryab);
        return res?.Path;
    }
}